<template>
	<!-- 消缺任务 执行 与 回执 -->
	<div>
		<div id="app" class="container">
		  <!--查询模块-->
		<div class="row" >
		  <div class="col-12 text-right">
		    <form class="form-group form-inline justify-content-end">
			<div class="row mb-12">
			  <div class="col-md-6">
			    <span>任务编号</span>
			    <input class="form-control" type="search" v-model="psSolvetaskMain.solvetaskcode" placeholder="请输入查询字符">
			  </div>
			  <div class="col-md-6">
			    <span>工作单据</span>
				<select class="form-control" v-model="psSolvetaskMain.workdoctype">
					<option value="-1" selected>--请选择--</option>
					<option v-for="item in queryByDocType" :value="item.configvalueid" :key="item.id">
						{{ item.configvaluename }}
					</option>
				</select>
			  </div>
			  <div class="col-md-6">
			    <span>下发人</span>
			    <input class="form-control" type="search" v-model="psSolvetaskMain.issuedbyname" placeholder="">
			  </div>
			  <div class="col-md-6">
			    <span>下发时间</span>
			    <input class="form-control" type="datetime-local" v-model="psSolvetaskMain.issuedtime" placeholder="">
			  </div>
			</div>
			<div class="m-2">
			  <div >
			      <button class="btn btn-outline-success " @click.prevent="load()">查询</button>
			  </div>
			</div>

			
		  
		   
		    </form>
	
		  </div>
		</div>  <!--查询模块结束-->
		        <table  class="table table-striped table-hover table-bordered center">
		            <thead>
						<tr>
						               <td v-text="'任务编号'"></td>
						               <td v-text="'任务名称'"></td>
						               <td v-text="'工作单据'"></td>
						               <td v-text="'下发人'"></td>
						               <td v-text="'任务下发时间'"></td>
						               <td v-text="'任务状态'"></td>
						               <td v-text="'任务完成时间'"></td>
									   <td>操作</td>
						 </tr>
					</thead>
		            <tbody>
						<tr   v-for="o in list" >
						               <td v-text="o.solvetaskcode"></td>
						               <td v-text="o.solvetaskname"></td>
						               <td v-text="o.workdoctypename"></td>
						               <td v-text="o.issuedbyname"></td>
						               <td v-text="o.issuedtime"></td>
						              <td :style="{color: o.taskstatus === 1 ? 'goldenrod' : (o.taskstatus === 2 ? 'royalblue' : (o.taskstatus === 3 ? 'red' : (o.taskstatus === 4 ? 'green' : (o.taskstatus === 5 ? 'darkgreen' : (o.taskstatus === 6 ? 'darkred' : '')))))}" v-text="o.taskstatusname"></td>
						               <td v-text="o.finishtime"></td>
									  <td>
										   <div v-if="o.iscancel!=0">
											   <button type="button" v-if="o.taskstatus==1 || o.taskstatus==2 || o.taskstatus==3 || o.taskstatus==4 || o.taskstatus==5 || o.taskstatus==6"  class="btn btn-outline-primary" @click="$router.push({path:'/InfoSolvetask',query:{obj:o}})">查看</button>
											   										  
										   </div>
										   <div v-else>
											   <button type="button" v-if="o.taskstatus == 1 || o.taskstatus == 2 || o.taskstatus == 3 || o.taskstatus == 4 || o.taskstatus==5 || o.taskstatus==6" @click="$router.push({path:'/InfoSolvetask',query:{obj:o}})" class="btn btn-outline-primary">查看</button>
											   <button type="button" v-if="o.taskstatus==1 || o.taskstatus==3" class="btn btn-outline-primary"  @click="$router.push({path:'/InfoSolvetask',query:{obj:o,execute:'execute'}})">回执录入</button>
											   <button type="button" v-if="o.taskstatus==1 || o.taskstatus==2" class="btn btn-outline-primary" @click="execute(o)" >执行</button>
											   <button type="button" v-if=" o.taskstatus==6" class="btn btn-outline-primary" @click="$router.push({path:'/InfoSolvetask',query:{obj:o,execute:'execute'}})" >修改</button>
											   
										   </div>
										   
									   </td>
						</tr>
					</tbody> 
		        </table>
				
		         <!--分页-->
		        <!--显示分页信息-->
		        <div class="row  text-right">
		            <!--文字信息-->
		            <div class="col-md-6">
		                当前第 <input name="startPage"  :value="pageInfo.pageNum"  style="width: 20px"/>/{{pageInfo.pages}}页.一共 {{pageInfo.total}}条记录
		            </div>
		            <!--点击分页-->
		            <div class="col-md-6">
		                <nav aria-label="Page navigation example">
		                    <ul class="pagination">
		                        <li class="page-item"><a class="page-link" href="javascript:;" @click="pageInfo.pageNum=1;load( )">首页</a></li>
		                        <li class="page-item" :class="{'disabled':!pageInfo.hasPreviousPage}">
		                            <a class="page-link" href="javascript:;" @click="pageInfo.pageNum=pageInfo.pageNum-1;load()" aria-label="Previous">
		                                <span aria-hidden="true">&laquo;</span>
		                            </a>
		                        </li>
		                        <li class="page-item" v-for="p in pageInfo.navigatepageNums" :class="{'active':pageInfo.pageNum==p}"><a class="page-link"  href="javascript:;" @click="pageInfo.pageNum=p;load()" v-text="p"></a></li>
		                        <li class="page-item" :class="{'disabled':!pageInfo.hasNextPage}">
		                            <a class="page-link" href="javascript:;"  @click="pageInfo.pageNum=pageInfo.pageNum-0+1;load()" aria-label="Next">
		                                <span aria-hidden="true">&raquo;</span>
		                            </a>
		                        </li>
		                        <li class="page-item"><a class="page-link"  href="javascript:;" @click="pageInfo.pageNum=pageInfo.pages;load()">尾页</a></li>
		                    </ul>
		                </nav>
		            </div>
		        </div>
		        <!--分页结束-->
		</div>
	</div>
</template>

<script>
	import {psSolvetaskMain,
	queryBySolvetaskStatus,
	queryBySolver,
	updateSolverDetail,
	updatepsSolvetaskMain,
	queryByLikeTwo,
	queryByDocType
	} from '../../config/request.js' 
	export default {
		data(){
		    return  {
		       psSolvetaskMain:{
				workdoctype: '-1',
		       pageNum:'1',
		       pageSize:'3' 
		    },
			psSystemconfig:{}, //消缺任务状态 下拉框数据
		       list:[],
		       pageInfo:{},
			   value: [], // 双向绑定的值
			   TransferList: [], // Transfer 数据源
			   modalVisible: false ,// 控制模态框显示隐藏
			   updateSolvetDetailObj:{},
			   updateSolvetDetailObjs:{}, 
			   incode:0,// 消缺任务编号
			   inid:0,// 消缺任务id
			   updateObj:{} ,// 修改对象,
			   updateIscancelObj:{},// 修改是否取消 状态
			   queryByDocType: {}, // 工作单据类型 状态
		}
	},methods:{
	    load(){
	       this.psSolvetaskMain.pageNum=this.pageInfo.pageNum;
				queryByLikeTwo(this.psSolvetaskMain).then(json=>{
					this.pageInfo=json.data.pageInfo;
					this.list=json.data.pageInfo.list;
				});
				
				queryBySolvetaskStatus().then(json=>{
					this.psSystemconfig=json.data.queryBySolvetaskStatus
					console.log(this.psSystemconfig)
				})
				
				queryByDocType().then(json => {
					this.queryByDocType = json.data.queryByDocType
				})
				
	         
	    },
		execute(o){
			let flag = confirm("确定执行吗？")
			if(flag){
					o.taskstatus = 3
					o.taskstatusname = '执行中'
					// 修改 消缺 任务
					updatepsSolvetaskMain(o).then(json => {
						alert(json.message)
					
					})
			}
		},
		  showModal(id,inspectiontaskcode) {
			  console.log(inspectiontaskcode)
			  console.log(id)
			this.incode=inspectiontaskcode;
			this.inid=id;
			queryBySolver().then(json=>{
				this.TransferList=json.data.queryBySolver
			})
			  // 模态框
			this.modalVisible = true;
		},
		handleClose(done) {
			// 模态框
			// 可以在这里进行取消操作
			this.modalVisible = false;
			done(); // 关闭模态框
		},
		handleSave() {
			// 保存 transfer  的信息
			// 处理保存逻辑
			    // 获取所选的 value 和 desc
			    const selectedItems = this.TransferList.filter(item => this.value.includes(item.solvercode));
			    console.log('保存选择的内容:', selectedItems);
				
				 // 将选中的巡检员信息添加到数组中
				    const selectedInspectors = [];
				    selectedItems.forEach(item => {
						this.iname+=item.solvername+','
				        const inspector = {
							id:item.id,
				            solvercode: item.solvercode,
				            solvername: item.solvername
				        };
				        selectedInspectors.push(inspector);
				    });
				
					
				    // 将选中的消缺员信息赋给 updateSolvetDetailObj 对象
				    this.updateSolvetDetailObj = selectedInspectors;
					console.log(this.updateSolvetDetailObj)
					// 将所选的 desc 值赋给 psInspectiontaskMain.issuedByName
					
						this.updateSolvetDetailObj.forEach(item=>{
						this.updateSolvetDetailObjs.taskid= this.incode
						this.updateSolvetDetailObjs.id=item.id
						
						console.log(this.updateSolvetDetailObjs)
						updateSolverDetail(this.updateSolvetDetailObjs).then(json=>{
							
							this.updateObj.id=this.inid
							this.updateObj.taskstatus=2
							this.updateObj.taskstatusname='已分配'
							console.log(this.updateObj)
							updatepsSolvetaskMain(this.updateObj).then(json=>{
									alert(json.message) 
									
							})
							
						})
						 // 延迟一秒后执行销毁操作
						    setTimeout(() => {
						        this.$destroy(); // 销毁组件实例
						    }, 1000); // 延迟 1000 毫秒（即 1 秒）
							
					})
					
					this.modalVisible = false; // 关闭模态框
					//this.$router.push("/InspectionTask"); 
					
		},
	},mounted(){
	    this.load();
	}
}
</script>

<style>
</style>